package capillary;

import java.io.BufferedInputStream;
import java.util.Scanner;

public class Solution4 {
	public static void main(String[] args) {
	Scanner s = new Scanner(new BufferedInputStream(System.in));
	int t = s.nextInt();
	while(t-- > 0){
		int N = s.nextInt();
		int P = s.nextInt();
		int M = s.nextInt();
		
		int[][] graph = new int[N][N];
		
		while(P-- > 0) {
			int u = s.nextInt();
			int v = s.nextInt();
			int d = s.nextInt();
			graph[u][v] = d;
			graph[v][u] = d;
		}
		
		while(M-- > 0) {
			int u = s.nextInt();
			int v = s.nextInt();
			System.out.println(graph[u][v]);
		}
	}
	
	
	s.close();

	}
}
